package com.ciwong.epaper.modules.epaper.ui;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Color;
import android.net.TrafficStats;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.volley.TimeoutError;
import com.ciwong.ciwongwrite.utils.CWUtils;
import com.ciwong.epaper.R;
import com.ciwong.epaper.application.EApplication;
import com.ciwong.epaper.application.EpaperConstant;
import com.ciwong.epaper.bean.HideDownloadDialogBean;
import com.ciwong.epaper.modules.bookstore.bean.PublishWorkContent;
import com.ciwong.epaper.modules.epaper.adapter.ChooseWorkContentAdapter;
import com.ciwong.epaper.modules.epaper.adapter.TeaWorkContentExListAdapter;
import com.ciwong.epaper.modules.epaper.bean.CatalogueInfo;
import com.ciwong.epaper.modules.epaper.bean.FollowreadTextParagraphBean;
import com.ciwong.epaper.modules.epaper.bean.ListenSpeakExaminBean;
import com.ciwong.epaper.modules.epaper.bean.Module;
import com.ciwong.epaper.modules.epaper.bean.ModuleContent;
import com.ciwong.epaper.modules.epaper.bean.PublishResource;
import com.ciwong.epaper.modules.epaper.bean.ResourceContent;
import com.ciwong.epaper.modules.epaper.dao.EpaperDao;
import com.ciwong.epaper.modules.epaper.util.ClickUtil;
import com.ciwong.epaper.modules.epaper.util.EpaperJumpManager;
import com.ciwong.epaper.modules.me.bean.FavoritesBook;
import com.ciwong.epaper.modules.me.bean.FollowReadWordDetailBeans;
import com.ciwong.epaper.modules.me.bean.PublishBook;
import com.ciwong.epaper.modules.me.util.MeJumpManager;
import com.ciwong.epaper.modules.msg.bean.WorkContent;
import com.ciwong.epaper.util.BaseExtCallBack;
import com.ciwong.epaper.util.EConstants;
import com.ciwong.epaper.util.IntentFlag;
import com.ciwong.epaper.util.RequestCode;
import com.ciwong.epaper.util.SerializableManager;
import com.ciwong.eventbus.EventBus;
import com.ciwong.libs.utils.CWLog;
import com.ciwong.libs.utils.CWSys;
import com.ciwong.libs.utils.NetworkUtils;
import com.ciwong.mobilelib.i.BaseCallBack;
import com.ciwong.mobilelib.ui.BaseActivity;
import com.ciwong.mobilelib.utils.BaseIntentFlag;
import com.ciwong.mobilelib.utils.ContainerType;
import com.ciwong.mobilelib.utils.ThreadTask;
import com.ciwong.mobilelib.utils.ToastUtil;
import com.ciwong.mobilelib.widget.CWDialog;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 作业内容页面
 */
public class TeaWorkContentActivity extends BaseActivity {

    private ExpandableListView list_view;
    //书籍id
    private String mBookId;
    private String mCid;
    private LinearLayout list_nodata, mLlNoNet;
    private Button mBtnRetry;
    //布置过的内容集合
    private List<PublishBook> publishBookList;
    //书籍详情
    private FavoritesBook mEpaperInfo;
    private CatalogueInfo mCatalogueInfo;
    private Module mModule;
    private ChooseWorkContentAdapter chooseWorkContentAdapter;

    private boolean isformNewDesk = false;

    private ResourceContent resourceContent;

    private RelativeLayout go_to_publish_work;
    private ImageView close_choose_work_content;
    private ImageView work_folder;
    private ListView choose_work_content_list;
    private RelativeLayout work_content_count_lay;
    private TextView work_content_count_text;
    private TextView refAnswerTime_text;
    private LinearLayout work_content_lay;
    //作业内容
    private List<PublishWorkContent> publishWorkContentList = new ArrayList<>();
    private WorkContent mWorkContent;
    private Boolean isShow = false;

    private int requestCode;

    //预计作业耗时
    private int refAnswerTime;

    private Map<Integer, Module> versionIdMapMo = new HashMap<Integer, Module>();

    private ArrayList<Module> mModuleList = new ArrayList<>();
    private TeaWorkContentExListAdapter mContentListAdapter;

    //试题使用次数和得分率
    private List<PublishResource> publishResourceList = new ArrayList<>();
    //作业类型：1-书本作业 2-试卷作业，不填默认为 1
    private int workTag;
    //是否上锁
    private Boolean isLock = false;


    //获取通过Mobile连接收到的字节总数
    private long total_data = TrafficStats.getTotalRxBytes();

    /**
     * 模块内容
     */
    private List<ModuleContent> mResourceList = new ArrayList<>();
    private String mTitleName;

    @Override
    protected void preCreate() {
        isformNewDesk = getIntent().getBooleanExtra(BaseIntentFlag.INTENT_FLAG_FORM, false);
        workTag = getIntent().getIntExtra(IntentFlag.INTENT_FLAG_WORK_TAG, 1);
        tag = getIntent().getStringExtra(IntentFlag.INTENT_FLAG_TAG);
        requestCode = getIntent().getIntExtra(IntentFlag.INTENT_FLAG_REQUEST_CODE_FROM, 10010);
        publishWorkContentList = (List<PublishWorkContent>) getIntent().getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ_LIST);
        if (isformNewDesk) {
            mBookId = getIntent().getStringExtra(BaseIntentFlag.INTENT_FLAG_BOOKID);
            mCid = getIntent().getStringExtra(BaseIntentFlag.INTENT_FLAG_CID);
            mTitleName = getIntent().getStringExtra(BaseIntentFlag.INTENT_FLAG_TITLE);
        } else {
            mEpaperInfo = (FavoritesBook) getIntent()
                    .getSerializableExtra(BaseIntentFlag.INTENT_FLAG_OBJ);
            mCatalogueInfo = (CatalogueInfo) getIntent().getSerializableExtra(IntentFlag.INTENT_FLAG_CATALOGUE_INFO);


            //服务器没有数据所以先用死的
            if (mEpaperInfo != null) {
                mBookId = String.valueOf(mEpaperInfo.getPackageId());
            }

            if (mCatalogueInfo != null) {
                mCid = mCatalogueInfo.getId();
            }
        }

    }

    @Override
    protected int setView() {
        return R.layout.activity_work_content;
    }


    @Override
    protected void findViews() {
        titleBar = findViewById(R.id.activity_base_titlebar);
        list_view = findViewById(R.id.list_view);
        list_nodata = findViewById(R.id.list_nodata);
        mBtnRetry = findViewById(R.id.btn_retry);
        go_to_publish_work = findViewById(R.id.go_to_publish_work);
        mLlNoNet = findViewById(R.id.ll_no_net);

        work_folder = findViewById(R.id.work_folder);
        work_content_count_lay = findViewById(R.id.work_content_count_lay);
        work_content_count_text = findViewById(R.id.work_content_count_text);
        refAnswerTime_text = findViewById(R.id.refAnswerTime_text);
        work_content_lay = findViewById(R.id.work_content_lay);
        list_view.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
                return true;
            }
        });
        list_view.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {
                if (isLock) {
                    deblockingDialog(i, i1);
                    return true;
                } else {
                    return false;
                }
            }
        });
        go_to_publish_work.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //避免重复点击
                if (ClickUtil.isFastDoubleClick()) {
                    return;
                }
                if (null != publishWorkContentList && publishWorkContentList.size() > 0) {
                    //判断数据是否加载完毕
                    if (null != publishWorkContentList.get(publishWorkContentList.size() - 1).getFinish()) {
                        EpaperJumpManager.jumpToTeaPublishWork(R.id.go_back, TeaWorkContentActivity.this, tag, mEpaperInfo.getProductName(), mEpaperInfo.getServiceId(), publishWorkContentList, mEpaperInfo.getSubject());
                    }
                } else {
                    ToastUtil.INSTANCE.toastCenterError(getString(R.string.choose_work_content));
                }

            }
        });
        mBtnRetry.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                loadNetData();
            }
        });
        work_folder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (publishWorkContentList.size() == 0) {

                } else {
                    showBottomDiaLog();
                    chooseWorkContentAdapter = new ChooseWorkContentAdapter(publishWorkContentList, TeaWorkContentActivity.this);
                    choose_work_content_list.setAdapter(chooseWorkContentAdapter);
                }
            }
        });

    }

    /**
     * 设置作业内容
     *
     * @param code
     * @param versionId
     * @param resourceUrl  资源url
     * @param resourceName 资源名
     */
    public void setWorkCountAndTimeConsuming(int code, String versionId, String resourceUrl, String resourceName) {
        if (1 == code) {
            if (publishWorkContentList.size() > 1) {
                work_content_lay.setVisibility(View.VISIBLE);
                int workCount = publishWorkContentList.size() - 1;
                work_content_count_text.setText(workCount + "");

            } else {
                work_content_lay.setVisibility(View.GONE);
                bottomDialog.dismiss();
                //choose_work_content_lay.setVisibility(View.GONE);
            }
            for (int i = 0; i < mResourceList.size(); i++) {
                if (null != resourceUrl && !"".equals(resourceUrl)) {
                    if (resourceUrl.equals(mResourceList.get(i).getResourceUrl())) {
                        mResourceList.get(i).setIsChecked(2);
                        break;
                    }
                } else {
                    if (resourceName.equals(mResourceList.get(i).getResourceName())) {
                        mResourceList.get(i).setIsChecked(2);
                        break;
                    }
                }

            }
            for (int i = 0; i < publishWorkContentList.size(); i++) {
                if (null != resourceUrl && !"".equals(resourceUrl)) {
                    if (resourceUrl.equals(publishWorkContentList.get(i).getResourceUrl())) {
                        publishWorkContentList.remove(i);
                        break;
                    }
                } else {
                    if (resourceName.equals(publishWorkContentList.get(i).getResourceName())) {
                        publishWorkContentList.remove(i);
                        break;
                    }
                }
            }
            setWorkLong();
            mContentListAdapter.notifyDataSetChanged();

        } else {
            if (publishWorkContentList.size() > 0) {
                work_content_lay.setVisibility(View.VISIBLE);
                int workCount = publishWorkContentList.size();
                work_content_count_text.setText(workCount + "");

            } else {
                work_content_lay.setVisibility(View.GONE);
            }
        }

    }


    @Override
    protected void initEvent() {
        EventBus.getDefault().register(this);
    }

    @Override
    protected void init() {
        if (isformNewDesk) {
            setTitleText(mTitleName);
        } else {
            setTitleText(mCatalogueInfo.getName());
        }
        if (mEpaperInfo.getIsPwd() == 1) {
            isLock = true;
        }
        try {
            isShow = CWSys.getSharedBoolean(EConstants.SHARE_KEY_WORK_CONTENT_IS_SHOW_LSW_TIP, false);
        } catch (Exception e) {
        }
        mContentListAdapter = new TeaWorkContentExListAdapter(this, mModuleList, mEpaperInfo, isLock, isShow, mCatalogueInfo, TeaWorkContentActivity.this);
        list_view.setAdapter(mContentListAdapter);
    }

    @Override
    protected void loadData() {
        getPublishbook();
        getPublishResources();
    }

    /**
     * 缓存选择内容到本地
     */
    public void setLocalData() {
        SerializableManager.getInstance().serialize(SerializableManager.SerializeKey.SHARE_KEY_CHOOSE_WORK_CONTENT, (Serializable) publishWorkContentList);
        //SerializableManager.getInstance().serialize(SerializableManager.SerializeKey.SHARE_KEY_CHOOSE_WORK_MOUDEL,(Serializable) workNameList);
        CWSys.setSharedBoolean(EConstants.SHARE_KEY_WORK_CONTENT_IS_SHOW_LSW_TIP, true);


    }


    @Override
    protected void onResume() {
        if (!EventBus.getDownLoadInstance().isRegistered(this)) {
            EventBus.getDownLoadInstance().register(this);
        }
        super.onResume();
    }


    @Override
    protected void onStop() {
        if (EventBus.getDownLoadInstance().isRegistered(this) && !isTopActivity()) {
            EventBus.getDownLoadInstance().unregister(this);
            hideDownloadProgress();
        }
        super.onStop();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (EventBus.getDownLoadInstance().isRegistered(this)) {
            EventBus.getDownLoadInstance().unregister(this);
        }
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    /**
     * 获取保存本地作业内容
     */
    public void getLocalPublishWork() {
        ThreadTask.getInstance().executorDBThread(new Runnable() {
            @Override
            public void run() {
                SerializableManager.getInstance().deSerialize(SerializableManager.SerializeKey.SHARE_KEY_CHOOSE_WORK_CONTENT, new BaseCallBack() {
                    @Override
                    public void failed(int errorCode, Object data) {
                        updateUI();
                    }

                    @Override
                    public void failed(Object data) {
                        updateUI();

                    }

                    @Override
                    public void success(Object data) {
                        try {
                            if (data != null) {
                                //获取本地DownLoadInfos
                                publishWorkContentList = (ArrayList<PublishWorkContent>) data;
                                setCheckContent();
                            }
                            updateUI();
                        } catch (Exception e) {
                            e.getStackTrace();
                        }

                    }
                });
            }
        }, ThreadTask.ThreadPeriod.PERIOD_HIGHT);

    }

    /**
     * 设置选中的作业内容
     */
    public void setCheckContent() {
        if (null != mModuleList) {
            for (int i = 0; i < mModuleList.size(); i++) {
                if (null != mModuleList.get(i).getResourceList()) {
                    List<ModuleContent> moduleContents = mModuleList.get(i).getResourceList();
                    for (int i1 = 0; i1 < moduleContents.size(); i1++) {
                        for (int i2 = 0; i2 < publishWorkContentList.size(); i2++) {
                            if (null != moduleContents.get(i1).getResourceUrl() && !TextUtils.isEmpty(moduleContents.get(i1).getResourceUrl().trim()) && null != publishWorkContentList.get(i2).getResourceUrl()) {
                                if (moduleContents.get(i1).getResourceUrl().equals(publishWorkContentList.get(i2).getResourceUrl())) {
                                    moduleContents.get(i1).setIsChecked(1);
                                }
                            } else {
                                if (moduleContents.get(i1).getResourceName().equals(publishWorkContentList.get(i2).getResourceName())) {
                                    moduleContents.get(i1).setIsChecked(1);
                                }
                            }

                        }
                    }
                }
            }
            if (null != publishBookList && publishWorkContentList.size() > 0) {
                work_content_lay.setVisibility(View.VISIBLE);
                int workCount = publishWorkContentList.size();
                work_content_count_text.setText(workCount + "");
                                        /*if (null != chooseWorkContentAdapter){
                                            chooseWorkContentAdapter.setNewData(publishWorkContentList);
                                        }else {
                                            chooseWorkContentAdapter = new ChooseWorkContentAdapter(publishWorkContentList, TeaWorkContentActivity.this);
                                            choose_work_content_list.setAdapter(chooseWorkContentAdapter);
                                        }*/

                //mContentListAdapter.setWorkName(publishWorkContentList);
            } else {
                work_content_lay.setVisibility(View.GONE);
            }
        }
        setWorkLong();
    }

    /**
     * 设置作业详情
     */
    public void setWorkDetail() {
        if (null != publishWorkContentList && publishWorkContentList.size() > 0) {
            work_content_lay.setVisibility(View.VISIBLE);
            work_content_count_text.setText(publishWorkContentList.size() + "");
        } else {
            work_content_lay.setVisibility(View.GONE);
        }
    }

    /**
     * 设置作业时长
     */
    public void setWorkLong() {
        refAnswerTime = 0;
        if (null != publishWorkContentList) {
            for (int i = 0; i < publishWorkContentList.size(); i++) {
                refAnswerTime = refAnswerTime + publishWorkContentList.get(i).getRefLong();
            }
        }
        int workRefLong = ((int) (Math.ceil((double) refAnswerTime / 60)));
        if (workRefLong > 0) {
            SpannableStringBuilder chooseWorkLongText = new SpannableStringBuilder("预计 " + workRefLong + " 分钟");
            ForegroundColorSpan GreenSpan = new ForegroundColorSpan(Color.parseColor("#5ce191"));
            if (workRefLong >= 100) {
                chooseWorkLongText.setSpan(GreenSpan, 3, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else if (workRefLong < 100 && workRefLong >= 10) {
                chooseWorkLongText.setSpan(GreenSpan, 3, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else {
                chooseWorkLongText.setSpan(GreenSpan, 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            refAnswerTime_text.setVisibility(View.VISIBLE);
            refAnswerTime_text.setText(chooseWorkLongText);
        } else {
            refAnswerTime_text.setVisibility(View.GONE);
        }
    }


    /**
     * 获取资源内容统计信息
     *
     * @param parentVersionId
     * @param versionId
     * @param moduleId
     * @param resourceType    资源类型
     */
    public void getResourceStatisticsWeb(String parentVersionId, final String versionId, int moduleId, final String resourceType, final String resourceUrl, final String resourceName, final int index) {

        EpaperDao.getInstance().getResourceStatisticsWeb(parentVersionId, versionId, moduleId, resourceType, new BaseExtCallBack(TeaWorkContentActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {
            @Override
            public void failed(int errorCode, Object data) {
                super.failed(errorCode, data);
                hideCricleProgress();
                if (data instanceof TimeoutError) {
                    ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                }
            }

            @Override
            public void failed(Object data) {
                hideCricleProgress();
                if (!NetworkUtils.isOnline()) {
                    ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                    return;
                }
            }

            @Override
            public void success(Object data) {
                try {
                    if (null != data) {
                        resourceContent = (ResourceContent) data;
                        //workNameList.add(module);
                        if (ModuleContent.ResourceType.RESOURCE_TYPE_WORD.equals(resourceType)) {
                            //单词跟读
                            followreadWordDetails(versionId, resourceUrl, resourceName, resourceContent, 10, index, ModuleContent.ResourceType.RESOURCE_TYPE_WORD);
                        } else if (ModuleContent.ResourceType.RESOURCE_TYPE_DICTATION.equals(resourceType)) {
                            //报听写
                            followreadWordDetails(versionId, resourceUrl, resourceName, resourceContent, 25, index, ModuleContent.ResourceType.RESOURCE_TYPE_DICTATION);
                        } else if (ModuleContent.ResourceType.RESOURCE_TYPE_LESSON.equals(resourceType)) {
                            //句子跟读
                            followreadTextParagraph(versionId, resourceUrl, resourceName, resourceContent, index);
                        } else if (ModuleContent.ResourceType.RESOURCE_TYPE_LISTEN_SPEAK.equals(resourceType)) {
                            //听说模考
                            ListenSpeakExaminAtion(versionId, resourceUrl, resourceName, resourceContent, index);
                        } else if (ModuleContent.ResourceType.RESOURCE_TYPE_ONLINE_ANSWER.equals(resourceType)) {
                            //在线作答
                            examinationData(versionId, resourceUrl, resourceName, resourceContent, index);
                        } else {
                            int refWorkLong;
                            double sentenceTime;
                            int itemCount = 1;
                            if (0 == resourceContent.getRefAnswerTime()) {
                                sentenceTime = 0 == resourceContent.getDefAnswerTime() ? 1 : resourceContent.getDefAnswerTime();
                                if (resourceContent.getSmallQuesCount() > 0) {
                                    itemCount = resourceContent.getSmallQuesCount();
                                } else if (resourceContent.getBigQuesCount() > 0) {
                                    itemCount = resourceContent.getBigQuesCount();
                                } else if (resourceContent.getItemCount() > 0) {
                                    itemCount = resourceContent.getItemCount();
                                }
                                refWorkLong = (int) (Math.ceil(sentenceTime * itemCount));
                            } else {
                                refWorkLong = resourceContent.getRefAnswerTime() * 60;
                            }
                            PublishWorkContent publishWorkContent = new PublishWorkContent();
                            publishWorkContent.setRefLong(refWorkLong);
                            publishWorkContent.setCheckedResource("");
                            publishWorkContent.setTotalQuesNum(resourceContent.getItemCount());
                            publishWorkContent.setFinish(true);
                            publishWorkContent.setFavoritesBook(mEpaperInfo);
                            publishWorkContent.setWorkScore(resourceContent.getRefScore());
                            publishWorkContent.setPackageId(mBookId);
                            publishWorkContent.setcId(mCid);
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrl) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrl)) {
                                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceName) {
                                        if (resourceList.get(a).getResourceName().equals(resourceName)) {
                                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                                            break;
                                        }
                                    }
                                }
                            }
                            if (index == mModuleList.size() - 1) {
                                hideCricleProgress();
                            }
                        }
                    }
                } catch (Exception e) {

                }

            }
        });
    }

    /**
     * 设置资源数据
     */
    public void setData() {
        for (int i = 0; i < mModuleList.size(); i++) {
            List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
            for (int a = 0; a < resourceList.size(); a++) {
                //如果versionid为0时 ParentVersionId 代替 ParentVersionId为0时 versionId 代替
                if (resourceList.get(a).getVersionId().equals("0")) {
                    getResourceStatisticsWeb(resourceList.get(a).getParentVersionId(), resourceList.get(a).getParentVersionId(), mModuleList.get(i).getModuleInfo().getModuleId(), resourceList.get(a).getResourceType(), resourceList.get(a).getResourceUrl(), resourceList.get(a).getResourceName(), i);
                } else if (resourceList.get(a).getParentVersionId().equals("0")) {
                    getResourceStatisticsWeb(resourceList.get(a).getVersionId(), resourceList.get(a).getVersionId(), mModuleList.get(i).getModuleInfo().getModuleId(), resourceList.get(a).getResourceType(), resourceList.get(a).getResourceUrl(), resourceList.get(a).getResourceName(), i);
                } else {
                    getResourceStatisticsWeb(resourceList.get(a).getParentVersionId(), resourceList.get(a).getVersionId(), mModuleList.get(i).getModuleInfo().getModuleId(), resourceList.get(a).getResourceType(), resourceList.get(a).getResourceUrl(), resourceList.get(a).getResourceName(), i);
                }
            }

        }
    }

    /**
     * 获取趣配音资源
     *
     * @param parentVersionId
     * @param versionId
     * @param moduleId
     * @param resourceName
     * @param isSelect
     * @param publishWorkContent
     * @param resourceUrl
     * @param resourcelType
     * @param followreadTextParagraphBean
     * @param listenSpeakExaminBean
     */
    public void getDubVideoDetailFromNet(final String parentVersionId, final String versionId, final int moduleId, final String resourceName, final Boolean isSelect,
                                         final PublishWorkContent publishWorkContent, final String resourceUrl, final String resourcelType,
                                         final FollowreadTextParagraphBean followreadTextParagraphBean, final ListenSpeakExaminBean listenSpeakExaminBean) {
        EpaperDao.getInstance().getDubVideoDetail(versionId, new BaseExtCallBack(TeaWorkContentActivity.this) {
            @Override
            public void failed(int errorCode, Object data) {
                if (errorCode == 1) {
                    if (ModuleContent.ResourceType.RESOURCE_TYPE_LISTEN_SPEAK.equals(resourcelType)) {
                        //听说模考
                        EpaperJumpManager.jumpToListenSpeakChooseWorkHtml(R.id.go_back, TeaWorkContentActivity.this, resourceName, resourceUrl, versionId, isSelect, RequestCode.TeaWorkContent.LISTEN_SPRAK, listenSpeakExaminBean, publishWorkContent.getTotalWorkLong(), parentVersionId, moduleId, resourcelType, RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_LISTEN_SPEAK);
                    } else if (ModuleContent.ResourceType.RESOURCE_TYPE_LESSON.equals(resourcelType)) {
                        //同步跟读课文
                        EpaperJumpManager.jumpToChooseSentence(TeaWorkContentActivity.this, resourceName, resourceUrl, versionId, isSelect, followreadTextParagraphBean, publishWorkContent.getTotalWorkLong(), publishWorkContent.getRequirementContent(), parentVersionId, moduleId, resourcelType, mCatalogueInfo.getName(), RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_SENTENCE);
                    } else if (ModuleContent.ResourceType.RESOURCE_TYPE_ONLINE_ANSWER.equals(resourcelType)) {
                        //在线作答
                        EpaperJumpManager.jumpToListenSpeakChooseWorkHtml(R.id.go_back, TeaWorkContentActivity.this, resourceName, resourceUrl, versionId, isSelect, RequestCode.TeaWorkContent.ANSWER_ONLINE, listenSpeakExaminBean, publishWorkContent.getTotalWorkLong(), parentVersionId, moduleId, resourcelType, RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_LISTEN_SPEAK);
                    }
                }
                super.failed(errorCode, data);
            }

            @Override
            public void failed(Object data) {
                if (data instanceof TimeoutError) {
                    hideCricleProgress();
                    ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                }
                super.failed(data);

            }

            @Override
            public void success(Object data) {

                try {
                    if (data != null && data instanceof WorkContent) {
                        mWorkContent = (WorkContent) data;
                        if ("".equals(mWorkContent.getBgAudioUrl())) {
                            mWorkContent.setBgAudioUrl("https://rimg3.ciwong.net/6v68/tools/audios/bgTemplate.mp3");
                        }
                        if (null == mWorkContent.getVideoUrl() || "".equals(mWorkContent.getVideoUrl())) {
                            if (ModuleContent.ResourceType.RESOURCE_TYPE_LISTEN_SPEAK.equals(resourcelType)) {
                                //听说模考
                                //EpaperJumpManager.jumpToListenSpeakChooseWork(TeaWorkContentActivity.this,resourceName,resourceUrl,versionId,isSelect,RequestCode.TeaWorkContent.LISTEN_SPRAK,listenSpeakExaminBean,publishWorkContent.getRefLong(), RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_LISTEN_SPEAK);
                                EpaperJumpManager.jumpToListenSpeakChooseWorkHtml(R.id.go_back, TeaWorkContentActivity.this, resourceName, resourceUrl, versionId, isSelect, RequestCode.TeaWorkContent.LISTEN_SPRAK, listenSpeakExaminBean, publishWorkContent.getRefLong(), parentVersionId, moduleId, resourcelType, RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_LISTEN_SPEAK);
                            } else if (ModuleContent.ResourceType.RESOURCE_TYPE_LESSON.equals(resourcelType)) {
                                //同步跟读课文
                                EpaperJumpManager.jumpToChooseSentence(TeaWorkContentActivity.this, resourceName, resourceUrl, versionId, isSelect, followreadTextParagraphBean, publishWorkContent.getTotalWorkLong(), publishWorkContent.getRequirementContent(), parentVersionId, moduleId, resourcelType, mCatalogueInfo.getName(), RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_SENTENCE);
                            } else if (ModuleContent.ResourceType.RESOURCE_TYPE_ONLINE_ANSWER.equals(resourcelType)) {
                                //在线作答
                                EpaperJumpManager.jumpToListenSpeakChooseWorkHtml(R.id.go_back, TeaWorkContentActivity.this, resourceName, resourceUrl, versionId, isSelect, RequestCode.TeaWorkContent.ANSWER_ONLINE, listenSpeakExaminBean, publishWorkContent.getRefLong(), parentVersionId, moduleId, resourcelType, RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_LISTEN_SPEAK);
                            }
                        } else {
                            MeJumpManager.jumpToDubVideoDetailActivity(EpaperConstant.REQUEST_CODE_GET_VIDEO_MASTER_STATE, R.string.go_back,
                                    TeaWorkContentActivity.this, "", mWorkContent, "0", 0);
                        }

                        /*if (workType != 0) {
                            mWorkContent.setWorkType(workType);
                        }*/

                    }
                } catch (Exception e) {
                    e.getStackTrace();
                }
            }
        });
    }

    /**
     * 获取试题使用次数和得分率
     */
    public void getPublishResources() {
        EpaperDao.getInstance().getPublishResources(mBookId, mCid, new BaseCallBack() {
            @Override
            public void failed(int errorCode, Object data) {

            }

            @Override
            public void failed(Object data) {

            }

            @Override
            public void success(Object data) {
                if (null != data) {
                    publishResourceList = (List<PublishResource>) data;
                    mContentListAdapter.updatepublishResourceData(publishResourceList);
                }
            }
        });
    }

    /**
     * 获取布置过的作业
     */
    public void getPublishbook() {
        if (null != EApplication.getInstance().getUserInfoBase()) {
            EpaperDao.getInstance().getPublishbook(EApplication.getInstance().getUserInfoBase().getUserId(), EApplication.BRAND_ID, mEpaperInfo.getProductId(), new BaseExtCallBack(TeaWorkContentActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {
                @Override
                public void failed(int errorCode, Object data) {
                    super.failed(errorCode, data);
                    showCricleProgress();
                    loadNetData();
                    if (data instanceof TimeoutError) {
                        ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                    }
                }

                @Override
                public void failed(Object data) {
                    showCricleProgress();
                /*loadNetData();
                getLocalPublishWork();*/
                    if (!NetworkUtils.isOnline()) {
                        ToastUtil.INSTANCE.toastCenterError(getString(R.string.load_faild_check_net_work));
                        return;
                    }
                }

                @Override
                public void success(Object data) {
                    hideCricleProgress();
                    if (null != data) {
                        publishBookList = (List<PublishBook>) data;
                        if (null == mModuleList || mModuleList.size() == 0) {
                            showCricleProgress();
                            loadNetData();
                        } else {
                            setHasPublishWork();
                            if (null != publishWorkContentList && publishWorkContentList.size() > 0) {
                                setCheckContent();
                                updateUI();
                            } else {
                                getLocalPublishWork();
                            }
                        }

                    } else {
                        if (null == mModuleList || mModuleList.size() == 0) {
                            showCricleProgress();
                            loadNetData();
                        } else {
                            //setHasPublishWork();
                            if (null != publishWorkContentList && publishWorkContentList.size() > 0) {
                                setCheckContent();
                                updateUI();
                            } else {
                                getLocalPublishWork();
                            }
                        }

                    }
                }
            });
        } else {
            finish();
        }
    }

    /**
     * 获取作业内容
     */
    private void loadNetData() {

        EpaperDao.getInstance().getCatalogueResourceList(mBookId, mCid, null, isformNewDesk,

                new BaseExtCallBack(TeaWorkContentActivity.this, EApplication.getInstance().getUserInfoBase().getUserId() + "") {

                    @Override
                    public void success(final Object data) {
                        try {
                            //hideCricleProgress();
                            //设置书籍加锁状态
                            mModuleList = (ArrayList<Module>) data;
                            setData();

                            if (mEpaperInfo.getIsPwd() == 1) {
                                isLock = true;
                            }
                            if (null != publishBookList && publishBookList.size() != 0) {
                                setHasPublishWork();
                            }

                            if (mModuleList == null || mModuleList.size() == 0) {
                                showContainerType(ContainerType.TYPE_NO_DATA);
                            } else {
                                showContainerType(ContainerType.TYPE_HAVE_DATA);
                                SerializableManager.getInstance().serialize(SerializableManager.SerializeKey.SHARE_KEY_BOOK_CHAPTER + mBookId + mCid, mModuleList);
                                paraData();


                                /*if (isformNewDesk) {

                                } else {
                                    mDownLoadInfos = DownLoadDB.queryDownloadInfoByBookIdAndChapterId(mBookId, mCid, CatalogueInfo.PackageMode.PACKAGE_MODE_NEW);
                                    mDownLoadInfos = fillList(mResourceList);
                                }*/
                                //updateUI();
                                if (null != publishWorkContentList && publishWorkContentList.size() > 0) {
                                    setCheckContent();
                                    updateUI();
                                } else {
                                    getLocalPublishWork();
                                }

                            }

                        } catch (Exception e) {
                            e.getStackTrace();
                        }

                    }

                    @Override
                    public void failed(int errorCode, Object data) {
                        //网络获取失败了再走本地获取流程
                        //super.failed(errorCode, data);
                        hideCricleProgress();
                        if (mModuleList == null || mModuleList.size() == 0) {
                            if (!NetworkUtils.isOnline() || data instanceof TimeoutError) {
                                showContainerType(ContainerType.TYPE_NO_NET_FAILED);
                            } else if (errorCode != 17 && errorCode != 27) {
                                ToastUtil.INSTANCE.toastCenterError(R.string.server_error);
                            }
                        }


                    }

                    @Override
                    public void failed(Object data) {
                        //                        getLocData();
                        super.failed(data);
                        if (mModuleList == null || mModuleList.size() == 0) {
                            if (!NetworkUtils.isOnline() || data instanceof TimeoutError) {
                                showContainerType(ContainerType.TYPE_NO_NET_FAILED);
                            }
                        }

                    }
                });
    }

    /**
     * 设置布置过的作业
     **/
    private void setHasPublishWork() {
        List<String> versionIds = new ArrayList<>();
        if (null != publishBookList && publishBookList.size() != 0) {
            for (int i = 0; i < publishBookList.size(); i++) {
                PublishBook publishBook = publishBookList.get(i);
                List<PublishBook.Subject> subjectList = publishBook.getSubjectList();
                for (int i1 = 0; i1 < subjectList.size(); i1++) {
                    versionIds.add(subjectList.get(i1).getVersionId());
                    for (int i3 = 0; i3 < mModuleList.size(); i3++) {
                        List<ModuleContent> resourceList = mModuleList.get(i3).getResourceList();
                        for (int i2 = 0; i2 < resourceList.size(); i2++) {
                            if (subjectList.get(i1).getVersionId().equals(resourceList.get(i2).getVersionId())||
                                    subjectList.get(i1).getResourceName().equals(resourceList.get(i2).getResourceName())) {
                                resourceList.get(i2).setHasDo(true);
                            }
                        }
                    }
                }
            }
        }
    }

    private EditText deblockint_edit;
    private RelativeLayout deblocking_cancel;
    private RelativeLayout deblocking_confirm_lay;
    private String pwd;
    private CWDialog cwDialog;

    public void deblockingDialog(final int groupIndex, final int childIndex) {
        cwDialog = new CWDialog(TeaWorkContentActivity.this);
        cwDialog.setCustomDialog(R.layout.activity_deblocking_dialog);
        deblockint_edit = cwDialog.findViewById(R.id.deblockint_edit);
        deblocking_cancel = cwDialog.findViewById(R.id.deblocking_cancel);
        deblocking_confirm_lay = cwDialog.findViewById(R.id.deblocking_confirm_lay);

        deblocking_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cwDialog.dismiss();
            }
        });
        deblocking_confirm_lay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pwd = deblockint_edit.getText().toString().trim();
                String tag = "22eb4d3820015070";
                String[] str = {pwd, tag};
                StringBuffer pwdstr = new StringBuffer();
                for (int i = 0; i < str.length; i++) {
                    if (i < str.length - 1) {
                        pwdstr.append(str[i] + "_");
                    } else if (i == str.length - 1) {
                        pwdstr.append(str[i]);
                    }
                }
                pwd = CWUtils.md5(CWUtils.md5(String.valueOf(pwdstr)));
                checkServicePwd(groupIndex, childIndex);
            }
        });
        cwDialog.show();
    }

    private Dialog bottomDialog;

    private void showBottomDiaLog() {
        bottomDialog = new Dialog(TeaWorkContentActivity.this, R.style.BottomDialog);
        View contentView = LayoutInflater.from(TeaWorkContentActivity.this).inflate(R.layout.activity_workcontent_bottom_dialog, null);
        close_choose_work_content = contentView.findViewById(R.id.close_choose_work_content);
        choose_work_content_list = contentView.findViewById(R.id.choose_work_content_list);
        bottomDialog.setContentView(contentView);
        Window window = bottomDialog.getWindow();
        window.setGravity(Gravity.BOTTOM);
        ViewGroup.LayoutParams layoutParams = contentView.getLayoutParams();
        layoutParams.width = getResources().getDisplayMetrics().widthPixels;
        layoutParams.height = getResources().getDisplayMetrics().heightPixels / 3;
        contentView.setLayoutParams(layoutParams);
        close_choose_work_content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //choose_work_content_lay.setVisibility(View.GONE);
                bottomDialog.dismiss();
            }
        });
        bottomDialog.show();
    }


    public void checkServicePwd(final int groupIndex, final int childIndex) {
        EpaperDao.getInstance().checkServicePwd(pwd, 3, mEpaperInfo.getProductId(), mEpaperInfo.getServiceId(), "", EApplication.BRAND_ID, new BaseCallBack() {
            @Override
            public void failed(int errorCode, Object data) {
                if (errorCode == 1) {
                    ToastUtil.INSTANCE.toastCenterError("密码错误");
                }
            }

            @Override
            public void failed(Object data) {

            }

            @Override
            public void success(Object data) {
                cwDialog.dismiss();
                isLock = false;
                mContentListAdapter.updateData(mModuleList, publishWorkContentList, isLock);
                super.success(data);
            }
        });
    }


    private void showContainerType(ContainerType containerType) {
        if (containerType == ContainerType.TYPE_NO_NET_FAILED) {
            mLlNoNet.setVisibility(View.VISIBLE);
            list_view.setVisibility(View.GONE);
            list_nodata.setVisibility(View.GONE);
        } else if (containerType == ContainerType.TYPE_NO_DATA) {
            list_nodata.setVisibility(View.VISIBLE);
            mLlNoNet.setVisibility(View.GONE);
            list_view.setVisibility(View.GONE);
        } else {
            list_view.setVisibility(View.VISIBLE);
            mLlNoNet.setVisibility(View.GONE);
            list_nodata.setVisibility(View.GONE);
        }

    }

    private void paraData() {
        versionIdMapMo.clear();
        mResourceList.clear();
        for (Module module : mModuleList) {
            List<ModuleContent> moduleContentList = module.getResourceList();
            if (null != moduleContentList && moduleContentList.size() > 0) {
                for (int i = 0; i < moduleContentList.size(); i++) {
                    ModuleContent moduleContent = moduleContentList.get(i);
                    if (TextUtils.isEmpty(moduleContent.isDeleted) || !moduleContent.isDeleted.equals("1")) {//单元没有被删除
                        mResourceList.add(moduleContentList.get(i));
                        versionIdMapMo.put(mResourceList.size(), module);
                    }
                }
            }
        }


    }

    private void updateUI() {
        mContentListAdapter.updateData(mModuleList, publishWorkContentList, isLock);
        for (int i = 0; i < mContentListAdapter.getGroupCount(); i++) {
            list_view.expandGroup(i);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {

            if (resultCode == RESULT_OK) {
                switch (requestCode) {
                    //选择单词返回数据
                    case RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_WORD:
                        String checkResource = data.getStringExtra(IntentFlag.INTENT_FLAG_WORD_DETAILS);
                        String resourceUrl = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_URL);
                        String resourceName = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_NAME);
                        PublishWorkContent wordPublishWorkContent = (PublishWorkContent) data.getSerializableExtra(IntentFlag.INTENT_FLAG_WORK_CONTENT);
                        int workLong = data.getIntExtra(IntentFlag.INTENT_FLAG_WORK_LONG, 0);
                        int checkCount = 0;
                        String[] split = checkResource.split(",");
                        if (null != checkResource && !"".equals(checkResource)) {
                            checkCount = split.length;
                        }
                        boolean isNeedAddWord = true; //是否需要添加到布置作业集合中
                        FollowReadWordDetailBeans followReadWordDetailBeans = (FollowReadWordDetailBeans) data.getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ);
                        String jsonObject = data.getStringExtra(IntentFlag.INTENT_FLAG_JSONOBJECT);
                        //如果有选中的单词 则重新设置数据 没有则删除
                        if (checkCount != 0) {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrl && !"".equals(resourceUrl) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrl.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResource);
                                        publishWorkContentList.get(i).setTotalQuesNum(checkCount);
                                        publishWorkContentList.get(i).setRequirementContent(jsonObject.toString());
                                        publishWorkContentList.get(i).setRefLong(workLong);
                                        publishWorkContentList.get(i).setFollowReadWordDetailBeans(followReadWordDetailBeans);
                                        isNeedAddWord = false;
                                        break;
                                    }
                                } else if (null != resourceName && !"".equals(resourceName) && null != publishWorkContentList.get(i).getResourceName()) {
                                    if (resourceName.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResource);
                                        publishWorkContentList.get(i).setTotalQuesNum(checkCount);
                                        publishWorkContentList.get(i).setRequirementContent(jsonObject.toString());
                                        publishWorkContentList.get(i).setRefLong(workLong);
                                        publishWorkContentList.get(i).setFollowReadWordDetailBeans(followReadWordDetailBeans);
                                        isNeedAddWord = false;
                                        break;
                                    }
                                }
                            }
                        } else {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrl && !"".equals(resourceUrl) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrl.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddWord = false;
                                        break;
                                    }
                                } else if (null != resourceName && !"".equals(resourceName) && null != publishWorkContentList.get(i).getResourceName()) {
                                    if (resourceName.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddWord = false;
                                        break;
                                    }
                                }
                            }
                        }
                        if (isNeedAddWord && checkCount != 0) {
                            wordPublishWorkContent.setcId(mCid);
                            wordPublishWorkContent.setPackageId(mBookId);
                            wordPublishWorkContent.setWorkName(mCatalogueInfo.getName());
                            wordPublishWorkContent.setFinish(true);
                            wordPublishWorkContent.setFavoritesBook(mEpaperInfo);
                            wordPublishWorkContent.setIsFree(mEpaperInfo.getIsFree());
                            publishWorkContentList.add(wordPublishWorkContent);
                            //设置改作业为选中状态
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrl) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrl)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceName) {
                                        if (resourceList.get(a).getResourceName().equals(resourceName)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    }

                                }
                            }
                        } else if (checkCount == 0) {
                            //没有选中的单词 则刷新选中状态
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrl) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrl)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceName) {
                                        if (resourceList.get(a).getResourceName().equals(resourceName)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    }

                                }
                            }
                        }
                        setWorkDetail();
                        setWorkLong();
                        updateUI();
                        break;
                    //跳转到报听写
                    case RequestCode.TeaWorkContent.REQ_CODE_TO_DICTATION:
                        String checkResourceWord = data.getStringExtra(IntentFlag.INTENT_FLAG_WORD_DETAILS);
                        String resourceUrlWord = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_URL);
                        String resourceNameWord = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_NAME);
                        int workLongWord = data.getIntExtra(IntentFlag.INTENT_FLAG_WORK_LONG, 0);
                        PublishWorkContent dictatPublishWorkContent = (PublishWorkContent) data.getSerializableExtra(IntentFlag.INTENT_FLAG_WORK_CONTENT);
                        int dictatCheckCount = 0;
                        String[] dictatSplit = checkResourceWord.split(",");
                        if (null != checkResourceWord && !"".equals(checkResourceWord)) {
                            dictatCheckCount = dictatSplit.length;
                        }
                        boolean isNeedAddDictat = true; //是否需要添加到布置作业集合中
                        FollowReadWordDetailBeans followReadWordDictionDetailBeans = (FollowReadWordDetailBeans) data.getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ);
                        if (dictatCheckCount != 0) {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrlWord && !"".equals(resourceUrlWord) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrlWord.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResourceWord);
                                        publishWorkContentList.get(i).setTotalQuesNum(dictatCheckCount);
                                        publishWorkContentList.get(i).setRefLong(workLongWord);
                                        publishWorkContentList.get(i).setFollowReadWordDetailBeans(followReadWordDictionDetailBeans);
                                        isNeedAddDictat = false;
                                        break;
                                    }
                                } else {
                                    if (resourceNameWord.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResourceWord);
                                        publishWorkContentList.get(i).setTotalQuesNum(dictatCheckCount);
                                        publishWorkContentList.get(i).setRefLong(workLongWord);
                                        publishWorkContentList.get(i).setFollowReadWordDetailBeans(followReadWordDictionDetailBeans);
                                        isNeedAddDictat = false;
                                        break;
                                    }
                                }

                            }
                        } else {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrlWord && !"".equals(resourceUrlWord) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrlWord.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddDictat = false;
                                        break;
                                    }
                                } else {
                                    if (resourceNameWord.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddDictat = false;
                                        break;
                                    }
                                }

                            }
                        }

                        if (isNeedAddDictat && dictatCheckCount != 0) {
                            dictatPublishWorkContent.setcId(mCid);
                            dictatPublishWorkContent.setPackageId(mBookId);
                            dictatPublishWorkContent.setWorkName(mCatalogueInfo.getName());
                            dictatPublishWorkContent.setFavoritesBook(mEpaperInfo);
                            dictatPublishWorkContent.setFinish(true);
                            publishWorkContentList.add(dictatPublishWorkContent);
                            //设置改作业为选中状态
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrlWord) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrlWord)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceNameWord) {
                                        if (resourceList.get(a).getResourceName().equals(resourceNameWord)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    }

                                }
                            }
                        } else if (dictatCheckCount == 0) {
                            //没有选中的单词 则刷新选中状态
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrlWord) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrlWord)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceNameWord) {
                                        if (resourceList.get(a).getResourceName().equals(resourceNameWord)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    }

                                }
                            }
                        }

                        setWorkDetail();
                        setWorkLong();
                        updateUI();
                        break;
                    //选择句子返回数据
                    case RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_SENTENCE:
                        String checkResourceSentence = data.getStringExtra(IntentFlag.INTENT_FLAG_WORD_DETAILS);
                        String resourceUrlSentence = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_URL);
                        String resourceNameSentence = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_NAME);
                        int chooseSenTenceWorkLong = data.getIntExtra(IntentFlag.INTENT_FLAG_WORK_LONG, 0);
                        PublishWorkContent publishWorkContent = (PublishWorkContent) data.getSerializableExtra(IntentFlag.INTENT_FLAG_WORK_CONTENT);
                        FollowreadTextParagraphBean followreadTextParagraphBean = (FollowreadTextParagraphBean) data.getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ);
                        String jsonObject2 = data.getStringExtra(IntentFlag.INTENT_FLAG_JSONOBJECT);
                        boolean isNeedAddContent = true; //是否需要添加到布置作业集合中
                        //如果有选中的句子 则重新设置数据 没有则删除
                        if (followreadTextParagraphBean.getCheckCount() != 0) {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrlSentence && !"".equals(resourceUrlSentence) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrlSentence.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResourceSentence);
                                        publishWorkContentList.get(i).setTotalQuesNum(followreadTextParagraphBean.getCheckCount());
                                        publishWorkContentList.get(i).setRequirementContent(jsonObject2);
                                        publishWorkContentList.get(i).setRefLong(chooseSenTenceWorkLong);
                                        publishWorkContentList.get(i).setFollowreadTextParagraphBean(followreadTextParagraphBean);
                                        isNeedAddContent = false;
                                        break;
                                    }
                                } else if (null != resourceNameSentence && !"".equals(resourceNameSentence) && null != publishWorkContentList.get(i).getResourceName() && !"".equals(publishWorkContentList.get(i).getResourceName())) {
                                    if (resourceNameSentence.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResourceSentence);
                                        publishWorkContentList.get(i).setTotalQuesNum(followreadTextParagraphBean.getCheckCount());
                                        publishWorkContentList.get(i).setRequirementContent(jsonObject2);
                                        publishWorkContentList.get(i).setRefLong(chooseSenTenceWorkLong);
                                        publishWorkContentList.get(i).setFollowreadTextParagraphBean(followreadTextParagraphBean);
                                        isNeedAddContent = false;
                                        break;
                                    }
                                }

                            }
                        } else {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrlSentence && !"".equals(resourceUrlSentence) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrlSentence.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddContent = false;
                                        break;
                                    }
                                } else if (null != resourceNameSentence && !"".equals(resourceNameSentence) && null != publishWorkContentList.get(i).getResourceName() && !"".equals(publishWorkContentList.get(i).getResourceName())) {
                                    if (resourceNameSentence.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddContent = false;
                                        break;
                                    }
                                }

                            }
                        }
                        if (isNeedAddContent && followreadTextParagraphBean.getCheckCount() != 0) {
                            publishWorkContent.setcId(mCid);
                            publishWorkContent.setPackageId(mBookId);
                            publishWorkContent.setFavoritesBook(mEpaperInfo);
                            publishWorkContent.setFinish(true);
                            publishWorkContentList.add(publishWorkContent);
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrlSentence) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrlSentence)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceNameSentence) {
                                        if (resourceList.get(a).getResourceName().equals(resourceNameSentence)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    }

                                }
                            }

                        } else if (followreadTextParagraphBean.getCheckCount() == 0) {
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrlSentence) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrlSentence)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceNameSentence) {
                                        if (resourceList.get(a).getResourceName().equals(resourceNameSentence)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    }

                                }
                            }
                        }
                        setWorkDetail();
                        setWorkLong();
                        updateUI();
                        break;
                    //选择听说模考 在线作答返回数据
                    case RequestCode.TeaWorkContent.REQ_CODE_TO_CHOOSE_LISTEN_SPEAK:
                        String checkResourceListen = data.getStringExtra(IntentFlag.INTENT_FLAG_WORD_DETAILS);
                        String resourceUrlListen = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_URL);
                        String resourceNameListen = data.getStringExtra(IntentFlag.INTENT_FLAG_RESOURCE_NAME);
                        int chooseListenSpeakWorkLong = data.getIntExtra(IntentFlag.INTENT_FLAG_WORK_LONG, 0);
                        float chooseListenSpeakWorkScore = data.getFloatExtra(IntentFlag.INTENT_FLAG_WORK_SCORE, 0);
                        PublishWorkContent listenSpeakPublishWorkContent = (PublishWorkContent) data.getSerializableExtra(IntentFlag.INTENT_FLAG_WORK_CONTENT);
                        ListenSpeakExaminBean listenSpeakExaminBean = (ListenSpeakExaminBean) data.getSerializableExtra(IntentFlag.INTENT_FLAG_OBJ);
                        //String jsonObject3 = data.getStringExtra(IntentFlag.INTENT_FLAG_JSONOBJECT);
                        boolean isNeedAddListen = true; //是否需要添加到布置作业集合中
                        if (listenSpeakExaminBean.getCheckCount() != 0) {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrlListen && !"".equals(resourceUrlListen) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrlListen.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResourceListen);
                                        publishWorkContentList.get(i).setTotalQuesNum(listenSpeakExaminBean.getCheckCount());
                                        //publishWorkContentList.get(i).setRequirementContent(jsonObject3.toString());
                                        publishWorkContentList.get(i).setWorkScore(chooseListenSpeakWorkScore);
                                        publishWorkContentList.get(i).setRefLong(chooseListenSpeakWorkLong);
                                        publishWorkContentList.get(i).setListenSpeakExaminBean(listenSpeakExaminBean);
                                        isNeedAddListen = false;
                                        break;
                                    }
                                } else {
                                    if (resourceNameListen.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.get(i).setCheckedResource(checkResourceListen);
                                        publishWorkContentList.get(i).setTotalQuesNum(listenSpeakExaminBean.getCheckCount());
                                        //publishWorkContentList.get(i).setRequirementContent(jsonObject3.toString());
                                        publishWorkContentList.get(i).setWorkScore(chooseListenSpeakWorkScore);
                                        publishWorkContentList.get(i).setRefLong(chooseListenSpeakWorkLong);
                                        publishWorkContentList.get(i).setListenSpeakExaminBean(listenSpeakExaminBean);
                                        isNeedAddListen = false;
                                        break;
                                    }
                                }
                            }
                        } else {
                            for (int i = 0; i < publishWorkContentList.size(); i++) {
                                if (null != resourceUrlListen && !"".equals(resourceUrlListen) && null != publishWorkContentList.get(i).getResourceUrl() && !"".equals(publishWorkContentList.get(i).getResourceUrl())) {
                                    if (resourceUrlListen.equals(publishWorkContentList.get(i).getResourceUrl())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddListen = false;
                                        break;
                                    }
                                } else {
                                    if (resourceNameListen.equals(publishWorkContentList.get(i).getResourceName())) {
                                        publishWorkContentList.remove(i);
                                        isNeedAddListen = false;
                                        break;
                                    }
                                }
                            }
                        }
                        if (isNeedAddListen && listenSpeakExaminBean.getCheckCount() != 0) {
                            listenSpeakPublishWorkContent.setcId(mCid);
                            listenSpeakPublishWorkContent.setPackageId(mBookId);
                            listenSpeakPublishWorkContent.setWorkName(mCatalogueInfo.getName());
                            listenSpeakPublishWorkContent.setFavoritesBook(mEpaperInfo);
                            listenSpeakPublishWorkContent.setFinish(true);
                            publishWorkContentList.add(listenSpeakPublishWorkContent);
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrlListen) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrlListen)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceNameListen) {
                                        if (resourceList.get(a).getResourceName().equals(resourceNameListen)) {
                                            resourceList.get(a).setIsChecked(1);
                                            break;
                                        }
                                    }

                                }
                            }

                        } else if (listenSpeakExaminBean.getCheckCount() == 0) {
                            for (int i = 0; i < mModuleList.size(); i++) {
                                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                                for (int a = 0; a < resourceList.size(); a++) {
                                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrlListen) {
                                        if (resourceList.get(a).getResourceUrl().equals(resourceUrlListen)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceNameListen) {
                                        if (resourceList.get(a).getResourceName().equals(resourceNameListen)) {
                                            resourceList.get(a).setIsChecked(2);
                                            break;
                                        }
                                    }

                                }
                            }
                        }
                        setWorkDetail();
                        setWorkLong();
                        updateUI();
                        break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取在线作答内容
     */
    public void examinationData(final String versionid, final String resourceUrl, final String resourceName, final ResourceContent resourceContent, final int index) {
        try {
            PublishWorkContent publishWorkContent = new PublishWorkContent();
                /*if (0 != listenSpeakExAminAtion.getRef_answer_time()) {
                    publishWorkContent.setRefLong(listenSpeakExAminAtion.getRef_answer_time());
                }*/
            publishWorkContent.setCheckedResource("");
            publishWorkContent.setTotalQuesNum(resourceContent.getBigQuesCount());
            //publishWorkContent.setListenSpeakExaminBean(listenSpeakExaminBean);

            int refWorkLong;
            double sentenceTime;
            int itemCount = 1;
            if (0 == resourceContent.getRefAnswerTime()) {
                sentenceTime = 0 == resourceContent.getDefAnswerTime() ? 1 : resourceContent.getDefAnswerTime();
                if (resourceContent.getSmallQuesCount() > 0) {
                    itemCount = resourceContent.getSmallQuesCount();
                } else if (resourceContent.getBigQuesCount() > 0) {
                    itemCount = resourceContent.getBigQuesCount();
                } else if (resourceContent.getItemCount() > 0) {
                    itemCount = resourceContent.getItemCount();
                }
                refWorkLong = (int) (Math.ceil(sentenceTime * itemCount));
            } else {
                refWorkLong = resourceContent.getRefAnswerTime() * 60;
            }

            publishWorkContent.setRefLong(refWorkLong);
            publishWorkContent.setTotalWorkLong(refWorkLong);
            publishWorkContent.setFavoritesBook(mEpaperInfo);
            publishWorkContent.setWorkScore(resourceContent.getRefScore());
            publishWorkContent.setPackageId(mBookId);
            publishWorkContent.setcId(mCid);

            //设置得分率和布置总次数
            if (null != publishResourceList && publishResourceList.size() > 0) {
                for (int i = 0; i < publishResourceList.size(); i++) {
                    if (publishResourceList.get(i).getResourceType().equals(ModuleContent.ResourceType.RESOURCE_TYPE_ONLINE_ANSWER) && publishResourceList.get(i).getVersionId().equals(versionid)) {
                        publishWorkContent.setTotalNum(publishResourceList.get(i).getTotalNum());
                        float ScoringRate = (float) publishResourceList.get(i).getAvgScore() / publishResourceList.get(i).getWorkScore() * 100;
                        DecimalFormat df = new DecimalFormat("0.0");
                        publishWorkContent.setScoringRate(df.format(ScoringRate));
                        break;
                    }
                }
            }
            //publishWorkContentList.add(publishWorkContent);
            for (int i = 0; i < mModuleList.size(); i++) {
                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                for (int a = 0; a < resourceList.size(); a++) {
                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrl) {
                        if (resourceList.get(a).getResourceUrl().equals(resourceUrl)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceName) {
                        if (resourceList.get(a).getResourceName().equals(resourceName)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    }
                }
            }
            if (index == mModuleList.size() - 1) {
                hideCricleProgress();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 获取听说模考内容
     */
    private void ListenSpeakExaminAtion(final String versionid, final String resourceUrl, final String resourceName, final ResourceContent resourceContent, final int index) {
        try {
            PublishWorkContent publishWorkContent = new PublishWorkContent();
            publishWorkContent.setCheckedResource("");
            publishWorkContent.setTotalQuesNum(resourceContent.getBigQuesCount());
            double sentenceTime;
            sentenceTime = 0 == resourceContent.getDefAnswerTime() ? 180 : resourceContent.getDefAnswerTime();
            publishWorkContent.setRefLong((int) (Math.ceil(sentenceTime * resourceContent.getBigQuesCount())));
            publishWorkContent.setTotalWorkLong((int) (Math.ceil(sentenceTime * resourceContent.getBigQuesCount())));
            publishWorkContent.setFavoritesBook(mEpaperInfo);
            publishWorkContent.setWorkScore(resourceContent.getRefScore());
            publishWorkContent.setPackageId(mBookId);
            publishWorkContent.setcId(mCid);

            //设置得分率和布置总次数
            if (null != publishResourceList && publishResourceList.size() > 0) {
                for (int i = 0; i < publishResourceList.size(); i++) {
                    if (publishResourceList.get(i).getResourceType().equals(ModuleContent.ResourceType.RESOURCE_TYPE_LISTEN_SPEAK) && publishResourceList.get(i).getVersionId().equals(versionid)) {
                        publishWorkContent.setTotalNum(publishResourceList.get(i).getTotalNum());
                        float ScoringRate = (float) publishResourceList.get(i).getAvgScore() / publishResourceList.get(i).getWorkScore() * 100;
                        DecimalFormat df = new DecimalFormat("0.0");
                        publishWorkContent.setScoringRate(df.format(ScoringRate));
                        break;
                    }
                }
            }

            for (int i = 0; i < mModuleList.size(); i++) {
                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                for (int a = 0; a < resourceList.size(); a++) {
                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrl) {
                        if (resourceList.get(a).getResourceUrl().equals(resourceUrl)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceName) {
                        if (resourceList.get(a).getResourceName().equals(resourceName)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    }
                }
            }
            if (index == mModuleList.size() - 1) {
                hideCricleProgress();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 句子跟读
     *
     * @param versionid
     */
    private void followreadTextParagraph(final String versionid, final String resourceUrl, final String resourceName, final ResourceContent resourceContent, final int index) {
        try {

            PublishWorkContent publishWorkContent = new PublishWorkContent();
            publishWorkContent.setCheckedResource("");
            publishWorkContent.setTotalQuesNum(resourceContent.getSentenceCount());

            double sentenceTime;
            sentenceTime = 0 == resourceContent.getDefAnswerTime() ? 30 : resourceContent.getDefAnswerTime();
            publishWorkContent.setRefLong((int) (Math.ceil(sentenceTime * resourceContent.getSentenceCount())));
            publishWorkContent.setTotalWorkLong((int) (Math.ceil(sentenceTime * resourceContent.getSentenceCount())));
            publishWorkContent.setFavoritesBook(mEpaperInfo);
            publishWorkContent.setWorkScore(resourceContent.getRefScore());
            publishWorkContent.setPackageId(mBookId);
            publishWorkContent.setcId(mCid);

            //设置得分率和布置总次数
            if (null != publishResourceList && publishResourceList.size() > 0) {
                for (int i = 0; i < publishResourceList.size(); i++) {
                    if (publishResourceList.get(i).getResourceType().equals(ModuleContent.ResourceType.RESOURCE_TYPE_LESSON) && publishResourceList.get(i).getVersionId().equals(versionid)) {
                        publishWorkContent.setTotalNum(publishResourceList.get(i).getTotalNum());
                        float ScoringRate = (float) publishResourceList.get(i).getAvgScore() / publishResourceList.get(i).getWorkScore() * 100;
                        DecimalFormat df = new DecimalFormat("0.0");
                        publishWorkContent.setScoringRate(df.format(ScoringRate));
                        break;
                    }
                }
            }

            //publishWorkContentList.add(publishWorkContent);

            for (int i = 0; i < mModuleList.size(); i++) {
                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                for (int a = 0; a < resourceList.size(); a++) {
                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrl) {
                        if (resourceList.get(a).getResourceUrl().equals(resourceUrl)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceName) {
                        if (resourceList.get(a).getResourceName().equals(resourceName)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    }
                }
            }
            if (index == mModuleList.size() - 1) {
                hideCricleProgress();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 报听写或单词跟读
     *
     * @param versionid
     */
    public void followreadWordDetails(final String versionid, final String resourceUrl, final String resourceName, final ResourceContent resourceContent, final int second, final int index, final String resourceType) {
        try {
            double sentenceTime;
            sentenceTime = 0 == resourceContent.getDefAnswerTime() ? second : resourceContent.getDefAnswerTime();
            PublishWorkContent publishWorkContent = new PublishWorkContent();
            publishWorkContent.setRefLong((int) (Math.ceil(sentenceTime * resourceContent.getItemCount())));
            publishWorkContent.setTotalWorkLong((int) (Math.ceil(sentenceTime * resourceContent.getItemCount())));
            publishWorkContent.setCheckedResource("");
            publishWorkContent.setTotalQuesNum(resourceContent.getItemCount());
            publishWorkContent.setFavoritesBook(mEpaperInfo);
            publishWorkContent.setWorkScore(resourceContent.getRefScore());
            publishWorkContent.setPackageId(mBookId);
            publishWorkContent.setcId(mCid);
            //设置得分率和布置总次数
            if (null != publishResourceList && publishResourceList.size() > 0) {
                for (int i = 0; i < publishResourceList.size(); i++) {
                    if (publishResourceList.get(i).getResourceType().equals(resourceType) && publishResourceList.get(i).getVersionId().equals(versionid)) {
                        publishWorkContent.setTotalNum(publishResourceList.get(i).getTotalNum());
                        float ScoringRate = (float) publishResourceList.get(i).getAvgScore() / publishResourceList.get(i).getWorkScore() * 100;
                        DecimalFormat df = new DecimalFormat("0.0");
                        publishWorkContent.setScoringRate(df.format(ScoringRate));
                        break;
                    }
                }
            }
            for (int i = 0; i < mModuleList.size(); i++) {
                List<ModuleContent> resourceList = mModuleList.get(i).getResourceList();
                for (int a = 0; a < resourceList.size(); a++) {
                    if (null != resourceList.get(a).getResourceUrl() && !"".equals(resourceList.get(a).getResourceUrl()) && null != resourceUrl) {
                        if (resourceList.get(a).getResourceUrl().equals(resourceUrl)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    } else if (null != resourceList.get(a).getResourceName() && !"".equals(resourceList.get(a).getResourceName()) && null != resourceName) {
                        if (resourceList.get(a).getResourceName().equals(resourceName)) {
                            resourceList.get(a).setPublishWorkContent(publishWorkContent);
                            break;
                        }
                    }
                }
            }
            if (index == mModuleList.size() - 1) {
                hideCricleProgress();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //隐藏加载框
    public void onEventMainThread(HideDownloadDialogBean hideDownloadDialogBean) {
        hideDownloadProgress();
    }

    @Override
    public void finish() {
        setLocalData();
        setWorkContentResult();
        super.finish();
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

            finish();
            return true;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

    public void setWorkContentResult() {
        Intent data = new Intent();
        data.putExtra(IntentFlag.INTENT_FLAG_OBJ_LIST, (Serializable) publishWorkContentList);
        setResult(requestCode, data);
    }

}
